﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace Montana
{
    public partial class frmLogin : Form
    {
        #region Constructor
        public frmLogin()
        {
            InitializeComponent();
        }
        #endregion

        #region Click en Cancelar
        private void btnCancelar_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        #endregion

        #region Eventor Click en Aceptar
        private void btnAceptar_Click(object sender, EventArgs e)
        {
            try
            {

                //if (txtUsuario.Text == string.Empty)
                    //throw new AllInFuncException("Debe ingresar un nombre de usuario");

                Login();
            }
            //catch (AllInFuncException funEx)
            //{
            //    MessageBox.Show(funEx.Message, "All In");
            //}
            //catch (AllInTechException techEx)
            //{
            //    techEx.Loguear();
            //    MessageBox.Show(techEx.MensajePublico, "All In");
            //}
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Montana");
            }
        }
        #endregion

        #region txtPassword KeyPress
        private void txtPassword_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (e.KeyChar == (char)(Keys.Enter))
                {
                    Login();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Future Comandas");
            }
        }
        #endregion

        #region Login
        private void Login()
        {

            //if (AdmUsuarios.UsuarioExiste(txtUsuario.Text.ToUpper()))

            if(true)
            {
                frmPrincipal ventanaPrincipal = ((frmPrincipal)Application.OpenForms[0]);
              //  ventanaPrincipal.usuarioLogueado = user;
                ventanaPrincipal.estadoLabelLogin.Text = "Usuario logueado: " + txtUsuario.Text.ToUpper();
                DialogResult = DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("Usuario y/o password incorrectos!", "Montana");
                txtUsuario.Focus();
                txtUsuario.SelectAll();
            }


        }
        #endregion

        #region txtUsuario Evento Key Press
        private void txtUsuario_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (e.KeyChar == (char)(Keys.Enter))
                {
                    if (txtPassword.Text == string.Empty)
                    {
                        txtPassword.Focus();
                    }
                    else
                    {
                        Login();
                    }

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Future Comandas");
            }
        }

        #endregion

    }
}
